﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev.BusinessRules;
using FrienDev.Data;

public partial class Controls_Users_FriendsDetailList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ApiHelper.Instance.IsFriendsPage())
        {
            this.friendsList.DataSource = FriendRules.Instance.GetFriendsListByUserId(ApiHelper.Instance.GetRequestUserId(), -1);
            this.friendsList.DataBind();
            User user = UserRules.Instance.GetUserByUserId(ApiHelper.Instance.GetRequestUserId());
            if (!user.Gender)
            {
                userName.Text = "他的好友: " + user.FullName;
            }
            else
            {
                userName.Text = "她的好友: " + user.FullName;
            }
        }
        else
        {
            this.friendsList.DataSource = FriendRules.Instance.GetFriendsListByUserId(UserRules.Instance.GetCurrentUserId(), -1);
            this.friendsList.DataBind();
            userName.Text = "我的好友: "+UserRules.Instance.GetCurrentUser().FullName;
        }
    }

    protected void imgDataBindHandle(object sender, EventArgs e)
    {
        Image img = sender as Image;
        img.ImageUrl = ApiHelper.Instance.GetUserLogoUrl(img.ImageUrl);
    }

    protected void hyDataBindHandle(object sender, EventArgs e)
    {
        HyperLink hy = sender as HyperLink;
        hy.NavigateUrl = ApiHelper.Instance.GetUserHomepageLink(hy.NavigateUrl);
    }

    protected void removeFriendHandle(object sender, EventArgs e)
    {
        LinkButton lb = sender as LinkButton;
        FriendRules.Instance.RemoveFiend(UserRules.Instance.GetCurrentUserId(), lb.CommandName);
        Page_Load(null, null);
    }

    protected void removeBindHandle(object sender, EventArgs e)
    {
        if (ApiHelper.Instance.IsFriendsPage())
        {
            (sender as LinkButton).Visible = false;
        }
    }
}
